package com.coolcard.framework.exception;


import lombok.Getter;
import org.springframework.http.HttpStatus;

/**
 * 错误码枚举
 */
@Getter
public enum ErrorCode {
    SUCCESS(HttpStatus.OK, 200, "操作成功"),

    REQUEST_ERROR(HttpStatus.BAD_REQUEST, 400, "请求错误"),
    VALIDATE_FAILED(HttpStatus.BAD_REQUEST, 4001, "请求参数校验错误"),

    UNAUTHORIZED(HttpStatus.UNAUTHORIZED, 401, "用户认证异常"),
    USER_NOT_LOGIN(HttpStatus.UNAUTHORIZED, 4011, "用户未登录"),
    USER_LOGIN_FAILED(HttpStatus.UNAUTHORIZED, 4012, "用户名或密码错误"),
    USER_ACCOUNT_LOCKED(HttpStatus.UNAUTHORIZED, 4013, "用户已锁定"),
    USER_HAS_EXISTED(HttpStatus.UNAUTHORIZED, 4014, "用户名已存在"),

    FORBIDDEN(HttpStatus.FORBIDDEN, 403, "无访问权限"),
    TOKEN_INVALID(HttpStatus.FORBIDDEN, 4031, "访问令牌不合法"),
    TOKEN_EXPIRED(HttpStatus.FORBIDDEN, 4032, "访问令牌已过期"),
    REFRESH_TOKEN_INVALID(HttpStatus.FORBIDDEN, 4033, "更新令牌不合法"),

    NOT_FOUND(HttpStatus.NOT_FOUND, 404, "访问的资源不存在"),
    No_Such_Element(HttpStatus.NOT_FOUND, 4041, "无指定数据"),

    METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, 405, "请求方法不支持"),

    INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 500, "服务器错误"),
    SERVER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 5001, "服务器异常");


    private final HttpStatus status;    // 状态码
    private final int code;             // 错误码
    private final String title;         // 错误信息


    ErrorCode(HttpStatus status, int code, String message) {
        this.status = status;
        this.code = code;
        this.title = message;
    }
}
